//
//  SearchMapPoiModel.m
//  o_amap
//
//  Created by Q神 on 2021/4/12.
//

#import "SearchMapPoiModel.h"

@implementation SearchMapPoiModel

+ (NSArray<SearchMapPoiModel *> *)createSearchMapPoiModelWithArray:(NSArray<AMapPOI *> *)arrays {
    NSMutableArray<SearchMapPoiModel *> *models = [NSMutableArray array];
    for (AMapPOI *poi in arrays) {
        SearchMapPoiModel *model = [[SearchMapPoiModel alloc] init];
        model.poiId = poi.uid;
        model.adCode = poi.adcode;
        model.adName = poi.district;
        model.businessArea = poi.businessArea;
        model.cityCode = poi.citycode;
        model.cityName = poi.city;
        model.direction = poi.direction;
        model.distance = poi.distance;
        model.email = poi.email;
        model.indoorData = [SearchMapIndoorData createSearchMapIndoorData:poi.indoorData];
        model.isIndoorMap = poi.hasIndoorMap;
        model.latLonPoint = [LatLngModel initWithLat:poi.location.latitude withLng:poi.location.longitude];
        model.enter = [LatLngModel initWithLat:poi.enterLocation.latitude withLng:poi.enterLocation.longitude];
        model.exit = [LatLngModel initWithLat:poi.exitLocation.latitude withLng:poi.exitLocation.longitude];
        model.parkingType = poi.parkingType;
        model.photos = [SearchMapImage createSearchMapPoiModelWithArray:poi.images];
        model.poiExtension = [SearchMapPOIExtension createSearchMapPOIExtension:poi.extensionInfo];
        model.postcode = poi.postcode;
        model.provinceCode = poi.pcode;
        model.provinceName = poi.province;
        model.shopID = poi.shopID;
        model.snippet = poi.address;
        model.subPois = [SearchMapSubPOI createSearchMapMapSubPOIWithArray:poi.subPOIs];
        model.tel = poi.tel;
        model.title = poi.name;
        model.typeCode = poi.typecode;
        model.typeDes = poi.type;
        model.website = poi.website;
        model.gridCode = poi.gridcode;
        NSLog(@"model.latLonPoint.latitude,longitude == %@, %@", model.latLonPoint.latitude, model.latLonPoint.longitude);
        
        [models addObject:model];
    }
    return models;
}

@end


@implementation SearchMapGeoPoint

//经纬度转换成新的，这里搜索报错。。。。
+ (SearchMapGeoPoint *)createMapGeoPointWithLat:(CGFloat)lat withLng:(CGFloat)lng {
    SearchMapGeoPoint *model = [[SearchMapGeoPoint alloc] init];
    if (lat) {
        model.latitude = [NSNumber numberWithDouble:lat];
    }
    
    if (lng) {
        model.longitude = [NSNumber numberWithDouble:lng];
    }
    return model;
}

@end


@implementation SearchMapIndoorData

+ (SearchMapIndoorData *)createSearchMapIndoorData:(AMapIndoorData *)indoorData {
    SearchMapIndoorData *model = [[SearchMapIndoorData alloc] init];
    model.floor = indoorData.floor;
    model.floorName = indoorData.floorName;
    model.pid = indoorData.pid;
    return model;
}

@end


@implementation SearchMapImage

+ (NSArray<SearchMapImage *> *)createSearchMapPoiModelWithArray:(NSArray<AMapImage *> *)arrays {
    NSMutableArray<SearchMapImage *> *models = [NSMutableArray array];
    for (AMapImage *mapImage in arrays) {
        SearchMapImage *model = [[SearchMapImage alloc] init];
        model.title = mapImage.title;
        model.url = mapImage.url;
        [models addObject:model];
    }
    return models;
}

@end


@implementation SearchMapPOIExtension

+ (SearchMapPOIExtension *)createSearchMapPOIExtension:(AMapPOIExtension *)poiExtension {
    SearchMapPOIExtension *model = [[SearchMapPOIExtension alloc] init];
    model.rating = [NSString stringWithFormat:@"%f", poiExtension.rating];
    model.cost = [NSNumber numberWithFloat:poiExtension.cost];
    model.openTime = poiExtension.openTime;
    return model;
}

@end


@implementation SearchMapSubPOI

+ (NSArray<SearchMapSubPOI *> *)createSearchMapMapSubPOIWithArray:(NSArray<AMapSubPOI *> *)arrays {
    NSMutableArray<SearchMapSubPOI *> *models = [NSMutableArray array];
    for (AMapSubPOI *subPoi in arrays) {
        SearchMapSubPOI *model = [[SearchMapSubPOI alloc] init];
        model.poiId = subPoi.uid;
        model.title = subPoi.name;
        model.subName = subPoi.sname;
        model.latLonPoint = [SearchMapGeoPoint createMapGeoPointWithLat:subPoi.location.latitude withLng:subPoi.location.longitude];
        model.subTypeDes = subPoi.subtype;
        model.distance = subPoi.distance;
        [models addObject:model];
    }
    return models;
}

@end
